import requests


class Requests:
    # 全局变量，类变量，通过类名调用
    sess = requests.session()

    # **kwargs表示不定长数的参数，datas表示数据类
    def send_requeset(self, method, url, token=None, datas=None, headers=None, **kwargs):
        res = None
        if token == None:
            headers = {
                'bigsmarter': 'bb458421fce7a72ae623ca70e73d70b1',
                'deviceId': '13FABE8C-D75C-4780-AF7A-22DD1601AE58',
                'platform': '2',
                'appVersion': '4.0.0',
                'protocolVersion': '1'
            }
        else:
            headers = {
                'bigsmarter': 'bb458421fce7a72ae623ca70e73d70b1',
                'deviceId': '13FABE8C-D75C-4780-AF7A-22DD1601AE58',
                'platform': '2',
                'appVersion': '4.0.0',
                'protocolVersion': '1',
                'token': token
            }
        method = str(method).lower()
        if method == "get":
            res = Requests.sess.request(method=method, url=url, params=datas, headers=headers, **kwargs)
        elif method == "post":
            # datas不为空并且属于dict类型
            # if datas and isinstance(datas, dict):
                # 将datas转化为json的字符类型
                # datas = json.dumps(datas)
            res = Requests.sess.request(method=method, url=url, json=datas, headers=headers, **kwargs)
        else:
            pass
        return res

# requests = Requests()
